<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  

  
  <title>2018级计科1、计科2、网工、信安班第15周竞赛题 | Tootal World</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="前言本文中的题目做法仅供参考，不一定是最简单或是最正确的方法。每题附的程序源码均在当时通过了OJ测试，但随着时间的推移也有可能失效。作者水平有限，如有疏漏，在所难免，望留言指出。 AProblem A: 忽略大小写比较字符串大小逐个字符比较，遇到不同的就返回。当两个字符均为0时结束。忽略大小写，这里采用了将所有的大写字母转换成小写字母来处理。">
<meta name="keywords" content="C++">
<meta property="og:type" content="article">
<meta property="og:title" content="2018级计科1、计科2、网工、信安班第15周竞赛题">
<meta property="og:url" content="http://tootal.xyz/2018/12/10/2018级计科1、计科2、网工、信安班第15周竞赛题/index.html">
<meta property="og:site_name" content="Tootal World">
<meta property="og:description" content="前言本文中的题目做法仅供参考，不一定是最简单或是最正确的方法。每题附的程序源码均在当时通过了OJ测试，但随着时间的推移也有可能失效。作者水平有限，如有疏漏，在所难免，望留言指出。 AProblem A: 忽略大小写比较字符串大小逐个字符比较，遇到不同的就返回。当两个字符均为0时结束。忽略大小写，这里采用了将所有的大写字母转换成小写字母来处理。">
<meta property="og:locale" content="default">
<meta property="og:updated_time" content="2018-12-12T14:20:47.380Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="2018级计科1、计科2、网工、信安班第15周竞赛题">
<meta name="twitter:description" content="前言本文中的题目做法仅供参考，不一定是最简单或是最正确的方法。每题附的程序源码均在当时通过了OJ测试，但随着时间的推移也有可能失效。作者水平有限，如有疏漏，在所难免，望留言指出。 AProblem A: 忽略大小写比较字符串大小逐个字符比较，遇到不同的就返回。当两个字符均为0时结束。忽略大小写，这里采用了将所有的大写字母转换成小写字母来处理。">
  
    <link rel="alternate" href="../../../../atom.xml" title="Tootal World" type="application/atom+xml">
  
  
    <link rel="icon" href="http://tootal.xyz/favicon.png">
  
  
    <link href="http://fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="../../../../css/style.css">
</head>
</html>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="../../../../index.html" id="logo">Tootal World</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="../../../../index.html" id="subtitle">在时光的流逝中，逐渐成为更好的自己。</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="../../../../index.html">Home</a>
        
          <a class="main-nav-link" href="../../../../archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="../../../../atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
		<!--below use google search-->
        <!--%- search_form({button: '&#xF002;'}) %-->
		<!--below use baidu search-->
		 <!--form action="http://www.baidu.com/baidu" method="get" accept-charset="utf-8" class="search-form">
          <input type="search" name="word" maxlength="20" class="search-form-input" placeholder="Search">
          <input type="submit" value="" class="search-form-submit">
          <input name=tn type=hidden value="bds">
          <input name=cl type=hidden value="3">
          <input name=ct type=hidden value="2097152">
          <input type="hidden" name="si" value="tootal.xyz">
        </form-->
		<!--below use swiftype search-->
		<!--input type="search" name="word" maxlength="20" class="st-default-search-input" placeholder="Search"-->
		<input type="text" class="st-default-search-input">
		<script type="text/javascript">
			(function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){
			(w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t);
			e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e);
			})(window,document,'script','//s.swiftypecdn.com/install/v2/st.js','_st');
			_st('install','PwDt_XJKCzu2LMzrR5qV','2.0.0');
		</script>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-2018级计科1、计科2、网工、信安班第15周竞赛题" class="article article-type-post" itemscope="" itemprop="blogPost">
  <div class="article-meta">
    <a href="index.html" class="article-date">
  <time datetime="2018-12-10T10:05:25.000Z" itemprop="datePublished">2018-12-10</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      2018级计科1、计科2、网工、信安班第15周竞赛题
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="前言"><a href="index.html#前言" class="headerlink" title="前言"></a>前言</h1><p>本文中的题目做法仅供参考，不一定是最简单或是最正确的方法。<br>每题附的程序源码均在当时通过了OJ测试，但随着时间的推移也有可能失效。<br>作者水平有限，如有疏漏，在所难免，望留言指出。</p>
<h1 id="A"><a href="index.html#A" class="headerlink" title="A"></a>A</h1><p><a href="http://222.201.146.216/JudgeOnline/problem.php?cid=1740&amp;pid=0" target="_blank" rel="noopener">Problem A: 忽略大小写比较字符串大小</a><br>逐个字符比较，遇到不同的就返回。当两个字符均为0时结束。<br>忽略大小写，这里采用了将所有的大写字母转换成小写字母来处理。<br><a id="more"></a><br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">MyStrCmp</span><span class="params">(<span class="keyword">char</span> *pStr1,<span class="keyword">char</span> *pStr2)</span></span>&#123;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;;i++)&#123;</span><br><span class="line">		<span class="keyword">if</span>(pStr1[i]&gt;=<span class="string">'A'</span>&amp;&amp;pStr1[i]&lt;=<span class="string">'Z'</span>)pStr1[i]+=<span class="string">'a'</span>-<span class="string">'A'</span>;</span><br><span class="line">		<span class="keyword">if</span>(pStr2[i]&gt;=<span class="string">'A'</span>&amp;&amp;pStr2[i]&lt;=<span class="string">'Z'</span>)pStr2[i]+=<span class="string">'a'</span>-<span class="string">'A'</span>;</span><br><span class="line">		<span class="keyword">if</span>(pStr1[i]&gt;pStr2[i])<span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">		<span class="keyword">else</span> <span class="keyword">if</span>(pStr1[i]&lt;pStr2[i])<span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">		<span class="keyword">if</span>(pStr1[i]==<span class="number">0</span>&amp;&amp;pStr2[i]==<span class="number">0</span>)<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="keyword">char</span> s1[<span class="number">25</span>],s2[<span class="number">25</span>];</span><br><span class="line">	<span class="keyword">while</span>(<span class="built_in">cin</span>&gt;&gt;s1&gt;&gt;s2)&#123;</span><br><span class="line">		<span class="keyword">int</span> ans=MyStrCmp(s1,s2);</span><br><span class="line">		<span class="keyword">if</span>(ans==<span class="number">0</span>)<span class="built_in">printf</span>(<span class="string">"=\n"</span>);</span><br><span class="line">		<span class="keyword">else</span> <span class="keyword">if</span>(ans==<span class="number">1</span>)<span class="built_in">printf</span>(<span class="string">"&gt;\n"</span>);</span><br><span class="line">		<span class="keyword">else</span> <span class="keyword">if</span>(ans==<span class="number">-1</span>)<span class="built_in">printf</span>(<span class="string">"&lt;\n"</span>);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h1 id="B"><a href="index.html#B" class="headerlink" title="B"></a>B</h1><p><a href="http://222.201.146.216/JudgeOnline/problem.php?cid=1740&amp;pid=1" target="_blank" rel="noopener">Problem B: 超大整数加法</a><br>当数字远远超过已有的数据类型时，只有用字符串来读入处理了。<br>先读入，再把字符串中的字符转换成数字存到数组里。（注意存到数组里的顺序是相反的，方便进位）<br>然后按位相加，处理进位即可。<br>这里的top用来处理数字前面不需要的0。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstring&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="keyword">char</span> s1[<span class="number">305</span>],s2[<span class="number">305</span>];</span><br><span class="line">	<span class="keyword">int</span> a1[<span class="number">305</span>],a2[<span class="number">305</span>];</span><br><span class="line">	<span class="keyword">while</span>(<span class="built_in">cin</span>&gt;&gt;s1&gt;&gt;s2)&#123;</span><br><span class="line">		<span class="built_in">memset</span>(a1,<span class="number">0</span>,<span class="keyword">sizeof</span>(a1));</span><br><span class="line">		<span class="built_in">memset</span>(a2,<span class="number">0</span>,<span class="keyword">sizeof</span>(a2));</span><br><span class="line">		<span class="keyword">int</span> len1=<span class="built_in">strlen</span>(s1),len2=<span class="built_in">strlen</span>(s2);</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;len1;i++)&#123;</span><br><span class="line">			a1[len1-i<span class="number">-1</span>]=s1[i]-<span class="string">'0'</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;len2;i++)&#123;</span><br><span class="line">			a2[len2-i<span class="number">-1</span>]=s2[i]-<span class="string">'0'</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;len2;i++)&#123;</span><br><span class="line">			a1[i]+=a2[i];</span><br><span class="line">			<span class="keyword">if</span>(a1[i]&gt;=<span class="number">10</span>)&#123;</span><br><span class="line">				a1[i+<span class="number">1</span>]+=a1[i]/<span class="number">10</span>;</span><br><span class="line">				a1[i]%=<span class="number">10</span>;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">int</span> top=<span class="number">300</span>;</span><br><span class="line">		<span class="keyword">while</span>(a1[top]==<span class="number">0</span>)top--;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=top;i&gt;=<span class="number">0</span>;i--)&#123;</span><br><span class="line">			<span class="built_in">cout</span>&lt;&lt;a1[i];</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="built_in">cout</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="C"><a href="index.html#C" class="headerlink" title="C"></a>C</h1><p><a href="http://222.201.146.216/JudgeOnline/problem.php?cid=1740&amp;pid=2" target="_blank" rel="noopener">Problem C: 消费情况调查</a><br>按照题意模拟，这里交换元素用了algorithm库文件里的swap函数。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;algorithm&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">stu</span>&#123;</span></span><br><span class="line">	<span class="built_in">string</span> name;</span><br><span class="line">	<span class="keyword">int</span> ord,pay,back,actpay;</span><br><span class="line">	<span class="keyword">char</span> sex;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> n;</span><br><span class="line">	<span class="keyword">while</span>(<span class="built_in">cin</span>&gt;&gt;n)&#123;</span><br><span class="line">		stu s[<span class="number">105</span>];</span><br><span class="line">		<span class="keyword">int</span> Msum=<span class="number">0</span>,Wsum=<span class="number">0</span>;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)&#123;</span><br><span class="line">			<span class="built_in">cin</span>&gt;&gt;s[i].ord&gt;&gt;s[i].name&gt;&gt;s[i].sex&gt;&gt;s[i].pay&gt;&gt;s[i].back;</span><br><span class="line">			s[i].actpay=s[i].pay-s[i].back;</span><br><span class="line">			<span class="keyword">if</span>(s[i].sex==<span class="string">'M'</span>)Msum+=s[i].actpay;</span><br><span class="line">			<span class="keyword">else</span> <span class="keyword">if</span>(s[i].sex==<span class="string">'W'</span>)Wsum+=s[i].actpay;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;n;i++)&#123;</span><br><span class="line">			<span class="keyword">for</span>(<span class="keyword">int</span> j=i+<span class="number">1</span>;j&lt;=n;j++)&#123;</span><br><span class="line">				<span class="keyword">if</span>(s[i].actpay&lt;s[j].actpay)swap(s[i],s[j]);</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="built_in">cout</span>&lt;&lt;<span class="string">'M'</span>&lt;&lt;Msum&lt;&lt;<span class="string">" W"</span>&lt;&lt;Wsum&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)&#123;</span><br><span class="line">			<span class="keyword">if</span>(s[i].back&gt;=(s[i].pay/<span class="number">2.0</span>))<span class="built_in">cout</span>&lt;&lt;s[i].ord;</span><br><span class="line">			<span class="built_in">cout</span>&lt;&lt;s[i].name&lt;&lt;<span class="string">' '</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="built_in">cout</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="D"><a href="index.html#D" class="headerlink" title="D"></a>D</h1><p><a href="http://222.201.146.216/JudgeOnline/problem.php?cid=1740&amp;pid=3" target="_blank" rel="noopener">Problem D: Emirp</a><br>rev函数用于反转数字，check函数判断是否为质数。<br>这里采用了先预处理出10000以内的符合条件的数字，记录在is数组里。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cmath&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">rev</span><span class="params">(<span class="keyword">int</span> x)</span></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> ans=<span class="number">0</span>;</span><br><span class="line">	<span class="keyword">while</span>(x)&#123;</span><br><span class="line">		ans=ans*<span class="number">10</span>+x%<span class="number">10</span>;</span><br><span class="line">		x/=<span class="number">10</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> ans;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">check</span><span class="params">(<span class="keyword">int</span> x)</span></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> temp=<span class="keyword">int</span>(<span class="built_in">sqrt</span>(x)+<span class="number">1</span>);</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">2</span>;i&lt;temp;i++)&#123;</span><br><span class="line">		<span class="keyword">if</span>(x%i==<span class="number">0</span>)<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">int</span> is[<span class="number">10005</span>];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">2</span>;i&lt;=<span class="number">10000</span>;i++)&#123;</span><br><span class="line">		<span class="keyword">if</span>(check(i)&amp;&amp;check(rev(i)))&#123;</span><br><span class="line">			is[i]=<span class="number">1</span>;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">int</span> n;</span><br><span class="line">	<span class="keyword">while</span>(<span class="built_in">cin</span>&gt;&gt;n)&#123;</span><br><span class="line">		<span class="keyword">int</span> count=<span class="number">0</span>;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">2</span>;;i++)&#123;</span><br><span class="line">			<span class="keyword">if</span>(is[i])&#123;</span><br><span class="line">				<span class="built_in">cout</span>&lt;&lt;i;</span><br><span class="line">				count++;</span><br><span class="line">				<span class="keyword">if</span>(count%<span class="number">10</span>==<span class="number">0</span>&amp;&amp;count!=n)<span class="built_in">cout</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">				<span class="keyword">else</span> <span class="keyword">if</span>(count==n)&#123;</span><br><span class="line">					<span class="built_in">cout</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">					<span class="keyword">break</span>;</span><br><span class="line">				&#125;<span class="keyword">else</span> <span class="built_in">cout</span>&lt;&lt;<span class="string">' '</span>;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="E"><a href="index.html#E" class="headerlink" title="E"></a>E</h1><p><a href="http://222.201.146.216/JudgeOnline/problem.php?cid=1740&amp;pid=4" target="_blank" rel="noopener">Problem E: 数组位置交换及序号名次统计</a><br>由于只能用一个数组交换元素，这里利用了下标n以后的空间暂存。<br><del>（其实也可以不交换）</del><br>显然一个数的排名=大于这个数的个数+1<br>暴力枚举统计即可。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">swap</span><span class="params">(<span class="keyword">int</span> a[],<span class="keyword">int</span> m,<span class="keyword">int</span> n)</span></span>&#123;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=m;i++)&#123;</span><br><span class="line">		a[m+n+i]=a[i];</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)&#123;</span><br><span class="line">		a[i]=a[m+i];</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=m;i++)&#123;</span><br><span class="line">		a[n+i]=a[n+m+i];</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">sortNo</span><span class="params">(<span class="keyword">int</span> a[],<span class="keyword">int</span> m,<span class="keyword">int</span> n)</span></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> x=a[m];</span><br><span class="line">	<span class="keyword">int</span> t=<span class="number">1</span>;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)&#123;</span><br><span class="line">		<span class="keyword">if</span>(a[i]&gt;x)t++;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> t;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> n,m;</span><br><span class="line">	<span class="keyword">while</span>(<span class="built_in">cin</span>&gt;&gt;n&gt;&gt;m)&#123;</span><br><span class="line">		<span class="keyword">int</span> s[<span class="number">205</span>];</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)&#123;</span><br><span class="line">			<span class="built_in">cin</span>&gt;&gt;s[i];</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="built_in">cout</span>&lt;&lt;sortNo(s,m,n)&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">		swap(s,m,n-m);</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)&#123;</span><br><span class="line">			<span class="built_in">cout</span>&lt;&lt;s[i];</span><br><span class="line">			<span class="keyword">if</span>(i==n)<span class="built_in">cout</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">			<span class="keyword">else</span> <span class="built_in">cout</span>&lt;&lt;<span class="string">' '</span>;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="F"><a href="index.html#F" class="headerlink" title="F"></a>F</h1><p><a href="http://222.201.146.216/JudgeOnline/problem.php?cid=1740&amp;pid=5" target="_blank" rel="noopener">Problem F: 子串查找与替换</a><br>可以先把str字符串存到strtemp里。用p指向str字符串。p初始化为0。（可以理解为把str字符串清空）<br>再用i指向strtemp里的字符，逐个处理，对每个字符开始判断是否与find_str相同。<br>若相同则把replace_str字符串添加在str后面（利用p确定位置），并且i向后跳一段距离。<br>若不相同则直接把i指向的字符加在str后即可，最后在str末尾添加0截断。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstring&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">find_replace_str</span><span class="params">(<span class="keyword">char</span> str[],<span class="keyword">const</span> <span class="keyword">char</span> find_str[],<span class="keyword">const</span> <span class="keyword">char</span> replace_str[])</span></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> count=<span class="number">0</span>;</span><br><span class="line">	<span class="keyword">char</span> strtemp[<span class="number">105</span>];</span><br><span class="line">	<span class="built_in">strcpy</span>(strtemp,str);</span><br><span class="line">	<span class="keyword">int</span> p=<span class="number">0</span>;</span><br><span class="line">	<span class="keyword">int</span> lens=<span class="built_in">strlen</span>(str),lenf=<span class="built_in">strlen</span>(find_str),lenr=<span class="built_in">strlen</span>(replace_str);</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;lens;i++)&#123;</span><br><span class="line">		<span class="keyword">int</span> f=<span class="number">1</span>;</span><br><span class="line">		<span class="keyword">if</span>(i&lt;=lens-lenf)&#123;</span><br><span class="line">			<span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j&lt;lenf;j++)&#123;</span><br><span class="line">				<span class="keyword">if</span>(strtemp[i+j]!=find_str[j])&#123;</span><br><span class="line">					f=<span class="number">0</span>;</span><br><span class="line">					<span class="keyword">break</span>;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;<span class="keyword">else</span> f=<span class="number">0</span>;</span><br><span class="line">		<span class="keyword">if</span>(f)&#123;</span><br><span class="line">			<span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j&lt;lenr;j++)&#123;</span><br><span class="line">				str[p++]=replace_str[j];</span><br><span class="line">			&#125;</span><br><span class="line">			i+=lenf<span class="number">-1</span>;</span><br><span class="line">			count++;</span><br><span class="line">		&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">			str[p++]=strtemp[i];</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	str[p]=<span class="number">0</span>;</span><br><span class="line">	<span class="keyword">return</span> count;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="keyword">char</span> str[<span class="number">100</span>],find_str[<span class="number">20</span>],replace_str[<span class="number">20</span>];</span><br><span class="line">	<span class="built_in">memset</span>(str,<span class="number">0</span>,<span class="keyword">sizeof</span>(str));</span><br><span class="line">	<span class="keyword">int</span> replace_cnt=<span class="number">0</span>;</span><br><span class="line">	<span class="keyword">while</span>(<span class="built_in">cin</span>&gt;&gt;str&gt;&gt;find_str&gt;&gt;replace_str)&#123;</span><br><span class="line">		replace_cnt=find_replace_str(str,find_str,replace_str);</span><br><span class="line">		<span class="built_in">cout</span>&lt;&lt;replace_cnt&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">		<span class="built_in">cout</span>&lt;&lt;str&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">		<span class="built_in">memset</span>(str,<span class="number">0</span>,<span class="keyword">sizeof</span>(str));</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://tootal.xyz/2018/12/10/2018级计科1、计科2、网工、信安班第15周竞赛题/" data-id="cjpqil6ja00063gtkmycfbjct" class="article-share-link">Share</a>
      
      
        <a href="index.html#comments" class="article-comment-link">
          <span class="post-comments-count valine-comment-count" data-xid="/2018/12/10/2018级计科1、计科2、网工、信安班第15周竞赛题/" itemprop="commentCount"></span>
          Comments
        </a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="../../../../tags/C/index.html">C++</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="../../14/Minecraft-Server-Tootal-World/index.html" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Minecraft Server Tootal World
        
      </div>
    </a>
  
  
    <a href="../../06/2018级-C-第5章课后作业-计科1班、创新班、辅修班/index.html" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">2018级-C++-第5章课后作业(计科1班、创新班、辅修班)</div>
    </a>
  
</nav>

  
</article>



  <section id="comments" class="vcomment">

  </section>
</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/ACM/index.html">ACM</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/C/index.html">C++</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Math/index.html">Math</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Minecraft/index.html">Minecraft</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="../../../../tags/ACM/index.html" style="font-size: 20px;">ACM</a> <a href="../../../../tags/C/index.html" style="font-size: 20px;">C++</a> <a href="../../../../tags/Math/index.html" style="font-size: 15px;">Math</a> <a href="../../../../tags/Minecraft/index.html" style="font-size: 10px;">Minecraft</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="http://tootal.xyz/archives/2018/12/">December 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="http://tootal.xyz/archives/2018/11/">November 2018</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="../../21/Net-Cloud-Music&#32;List&#32;Download/index.html">Net-Cloud-Music List Download</a>
          </li>
        
          <li>
            <a href="../../21/三角函数和差化积、积化和差公式推导记忆/index.html">三角函数和差化积、积化和差公式推导记忆</a>
          </li>
        
          <li>
            <a href="../../17/《高级语言程序设计C++（一）》样卷/index.html">《高级语言程序设计C++（一）》样卷</a>
          </li>
        
          <li>
            <a href="../../14/Minecraft-Server-Tootal-World/index.html">Minecraft Server Tootal World</a>
          </li>
        
          <li>
            <a href="index.html">2018级计科1、计科2、网工、信安班第15周竞赛题</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2018 tootal<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="../../../../index.html" class="mobile-nav-link">Home</a>
  
    <a href="../../../../archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="../../../../fancybox/jquery.fancybox.css">
  <script src="../../../../fancybox/jquery.fancybox.pack.js"></script>


<script src="../../../../js/script.js"></script>




  <script src="http://cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="http://unpkg.com/valine/dist/Valine.min.js"></script>
<script>
    var GUEST_INFO = ['nick','mail','link'];
    var guest_info = 'nick,mail,link'.split(',').filter(function(item){
        return GUEST_INFO.indexOf(item) > -1
    });
    var notify = 'false' == true;
    var verify = 'false' == true;
    new Valine({
        el: '.vcomment',
        notify: notify,
        verify: verify,
        appId: "M3v8N5hOEvMyXAbssqMm35dx-gzGzoHsz",
        appKey: "cPadTqnA1Me5mlv0N4Ix96Xl",
        placeholder: "Please leave your footprints.",
        pageSize:'10',
        avatar:'mm',
        lang:'zh-cn'
    });
</script>

  </div>
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax: {
            inlineMath: [ ["$","$"], ["\\(","\\)"] ],
            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
            processEscapes: true
        }
    });
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax();
        for (var i = 0; i < all.length; ++i)
            all[i].SourceElement().parentNode.className += ' has-jax';
    });
</script>
<!--script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script>

</body>
</html>